package com.bitrate.dagger.server.websocket.handler;

import org.springframework.stereotype.Component;
import org.tio.core.ChannelContext;
import org.tio.core.Tio;
import org.tio.websocket.common.WsResponse;

import com.bitrate.dagger.sdk.websocket.enums.PushBizType;
import com.bitrate.dagger.sdk.websocket.enums.SystemPushType;
import com.bitrate.dagger.sdk.websocket.request.WebSocketRequest;

/**
 * 心跳包处理策略
 */
@Component
public class HeartBeatStrategy extends AbstractStrategyHandler {

	@Override
	public Boolean init(PushBizType type) {
		return SystemPushType.HEART_BEAT.getType().equals(type);
	}

	@Override
	public void execute(WebSocketRequest request, ChannelContext channelContext) {
		WsResponse wsResponse = WsResponse.fromText(SystemPushType.HEART_BEAT.getRemark(), "UTF-8");
		Tio.send(channelContext, wsResponse);
	}

}
